package com.lagou.mapper;

import com.lagou.pojo.Users;
import org.apache.ibatis.annotations.*;
import org.mybatis.caches.redis.RedisCache;

import java.util.List;

/**
 * @author srh
 * @CacheNamespace(implementation = RedisCache.class) 用来指定二级缓存的实现是采用redisCache
 * @date 2020/02/26
 **/
//@CacheNamespace(implementation = RedisCache.class)
public interface UsersMapper {

    /**
     * 查询所有orders
     *
     * @return
     */
    List<Users> xmlFindAllUserAndOrders();

    /**
     * 查询所有的roles
     *
     * @return
     */
    List<Users> xmlFindAllUserAndRoles();

    /**
     * 主键查询
     *
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    Users findById(Long id);

    @Select("select * from user")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "ordersList", column = "id", javaType = List.class,
                    many = @Many(select = "com.lagou.mapper.OrdersMapper.findByUid")),
            @Result(property = "rolesList", column = "id", javaType = List.class,
                    many = @Many(select = "com.lagou.mapper.RolesMapper.findByUid"))
    })
    List<Users> findAll();

    /**
     * 新增
     *
     * @param insertUser
     * @return
     */
    @Insert("insert into `user`(name) values(#{name})")
    int insert(Users insertUser);
}
